<?php

namespace App\Http\Requests;

use Illuminate\Database\Query\Builder;
use Illuminate\Validation\Rule;

/**
 * 家族史更新验证
 * Class FamilyHistoryUpdateRequest
 * @package App\Http\Requests
 */
class FamilyHistoryUpdateRequest extends FamilyHistoryStoreRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = parent::rules();

        $rules['id']        = [
            'required', 'integer', 'min:1',
            Rule::exists('st_medical_familyhistory', 'id')->where(function (Builder $query) {
                $query->where('record_id', $this->input('record_id'));
            }),
        ];

        return $rules;
    }

    public function messages()
    {
        $messages = parent::messages();

        unset($messages['record_id.required']);

        $messages['id.exists']                  = '家族史ID 不存在，或与病历ID不匹配。';
        $messages['record_id.required_without'] = '缺少家族史ID或病历ID。';

        return $messages;
    }
}
